package pers.cz.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * 消息生产者,
 * @program: PostGirl-panent
 * @description: RedisQueueProductor
 * @author: Cheng Zhi
 * @create: 2021-07-03 15:43
 **/
@Service
public class RedisQueueProductor {

    @Autowired
    JedisPool jedisPool;

    /**
     * 用于订阅发布模式
     * @param channel
     * @param message
     */
    public void putMessage(String channel, String message) {
        channel = "channel:" + channel;
        Jedis resource = jedisPool.getResource();
        resource.publish(channel, message);
        resource.close();
    }

    /**
     * 用于生产者消费者模式
     * @param message
     */
    public void putMessageForTestCase(String message) {
        Jedis resource = jedisPool.getResource();
        resource.lpush("RUNTESTCASEQUEUE", message);
        //resource.lpush("teset1",message);
        resource.close();

    }
}
